import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomePage.vue'

import PrivatePage from "@/views/PrivatePage.vue";
import writeArticle from '../views/article.vue'
import text from  '../views/text.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/Login.vue')
    },
    {
        path: '/labelSearch',
        name: 'labelSearch',
        component: () => import('../views/labelSearch.vue')
    },
    {
        path: '/admin',
        name: 'Admin',
        component: () => import('../views/admin.vue')
    },

    {
        path: '/privatePage',
        name: 'PrivatePage',
        component: () => import('../views/PrivatePage.vue'),
  },
  {
    path: '/showinfo',
    name: 'showinfo',
    component: () => import('../views/showinfo.vue'),
  },
  {
    path: '/infoeditor',
    name: 'infoeditor',
    component: () => import('../views/infoeditor.vue'),
  },
  {
    path: '/countcontrol',
    name: 'countcontrol',
    component: () => import('../views/countcontrol.vue'),
  },
  {
    path: '/checkFollow',
    name: 'checkFollow',
    component: () => import('../views/checkFollow.vue')
  },

    {
    path: '/imageUp',
    name: 'imageUp',
    component: () => import('../views/imageUp.vue'),
  },
  {
    path: '/articlecontrol',
    name: 'articlecontrol',
    component: () => import('../views/articlecontrol.vue'),


  },
  {
    path: '/writeArticle',
    name: 'writeArticle',
    component: () => import('../views/article.vue')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/register.vue')
  },
  {
    path:'/text',
    name:'text',
    component: ()=>import('../views/text.vue')
  },
  {
    path:'/search',
    name:'Search',
    component: ()=>import('../views/search.vue')
  },
  {
    path: '/userPage',
    name: 'userPage',
    component: () => import('../views/userPage.vue'),
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = error.message.match(pattern);
  if (isChunkLoadFailed) {
    window.location.reload();
    // router.replace(router.history.pending.fullPath);
  }else{
    console.log(error)
  }
});

export default router
